<?php
function readable_random_string($length = 6) {
    $conso = array("b", "c", "d", "f", "g", "h", "j", "k", "l",
        "m", "n", "p", "r", "s", "t", "v", "w", "x", "y", "z");
    $vocal = array("a", "e", "i", "o", "u", "0");
	$numbers = array("1", "2", "3", "4", "5", "6", "7", "8", "9");
    $password = "";
    srand((double) microtime() * 1000000);
    $max = $length / 2;
    for ($i = 1; $i <= $max; $i++) {
        $password.=$conso[rand(0, 19)];
        $password.=$vocal[rand(0, 4)];
		$password.=$numbers[rand(0,9)];
    }
    return $password;
}

//
function teaser_truncate($string, $limit, $break = ".", $pad = "...") {
// return with no change if string is shorter than $limit  
    if (strlen($string) <= $limit)
        return $string;

// is $break present between $limit and the end of the string?  
    if (false !== ($breakpoint = strpos($string, $break, $limit))) {
        if ($breakpoint < strlen($string) - 1) {
            $string = substr($string, 0, $breakpoint) . $pad;
        }
    }
    return $string;
}

function RandomQuoteByInterval($TimeBase, $QuotesArray) {

    // Make sure it is a integer
    $TimeBase = intval($TimeBase);

    // How many items are in the array?
    $ItemCount = count($QuotesArray);

    // By using the modulus operator we get a pseudo
    // random index position that is between zero and the
    // maximal value (ItemCount)
    $RandomIndexPos = ($TimeBase % $ItemCount);

    // Now return the random array element
    return $QuotesArray[$RandomIndexPos];
}

//
function String2Hex($string) {
    $hex = '';
    for ($i = 0; $i < strlen($string); $i++) {
        $hex .= dechex(ord($string[$i]));
    }
    return $hex;
}

//
function Hex2String($hex) {
    $string = '';
    for ($i = 0; $i < strlen($hex) - 1; $i+=2) {
        $string .= chr(hexdec($hex[$i] . $hex[$i + 1]));
    }
    return $string;
}

function path_get_last_arg($path) {
    $path = str_replace('\\', '/', $path);
    $path = preg_replace('/\/+$/', '', $path);
    $path = explode('/', $path);
    $l = count($path) - 1;
    return isset($path[$l]) ? $path[$l] : '';
}

function FormatAsKey($string) {

    $string = strtolower($string);

    // Fix german special chars
    $string = preg_replace('/[��]/', 'ae', $string);
    $string = preg_replace('/[��]/', 'ue', $string);
    $string = preg_replace('/[��]/', 'oe', $string);
    $string = preg_replace('/[�]/', 'ss', $string);

    // Replace other special chars
    $specialChars = array(
        'sharp' => '#', 'dot' => '.', 'plus' => '+',
        'and' => '&', 'percent' => '%', 'dollar' => '$',
        'equals' => '=',
    );

    while (list($replacement, $char) = each($specialChars))
        $string = str_replace($char, '-' . $replacement . '-', $string);

    $string = strtr(
            $string, "�����������������������������������������������������", "AAAAAAaaaaaaOOOOOOooooooEEEEeeeeCcIIIIiiiiUUUUuuuuyNn"
    );

    // Remove all remaining other unknown characters        
    $string = preg_replace('/[^a-z0-9\-]/', '-', $string);
    $string = preg_replace('/^[\-]+/', '', $string);
    $string = preg_replace('/[\-]+$/', '', $string);
    $string = preg_replace('/[\-]{2,}/', '-', $string);

    return $string;
}

function contains($str, $content, $ignorecase = true) {
    if ($ignorecase) {
        $str = strtolower($str);
        $content = strtolower($content);
    }
    return strpos($content, $str) ? true : false;
}


?>